package com.example.spinning.service;

import com.example.spinning.bean.DeliverOrder;
import com.example.spinning.mapper.DeliverOrderMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

@Service
public class DeliverOrderService {

    @Autowired
    private DeliverOrderMapper deliverOrderMapper;

    //得到出货单信息
    //带有分页功能的展现数据
    public List<DeliverOrder> getAllDeliverOrder(Integer page, Integer count) {
        int start = (page - 1) * count;
        return deliverOrderMapper.getDeliverOrder(start,count);
    }

    //找到行数
    public int getDeliverOrderCount() {
        return deliverOrderMapper.getCountDeliverOrder();
    }

    //根据条件找到行数
        public int getDeliverOrderCountByCondition(String date,String receiver,String norms,String batch_no){
        return deliverOrderMapper.getCountDeliverOrderByCondition(date,receiver,norms,batch_no);
    }

    //根据id查询出货单信息
    public DeliverOrder getDeliverOrderById(long id){
        DeliverOrder order = deliverOrderMapper.getDeliverOrderById(id);
        return order;
    }

    //根据条件模糊查询
    public List<DeliverOrder> getDeliverOrderByCondition(Integer page, Integer count,String date,String receiver,String norms,String batch_no){
        int start = (page - 1) * count;
        return deliverOrderMapper.getDeliverOrderByCondition(start,count,date,receiver,norms,batch_no);
    }

    //添加出货单信息
    public int addDeliverOrder(DeliverOrder order){
        return deliverOrderMapper.addDdeliverOrder(order);
    }


    //修改
    public int updateDeliverOrder(DeliverOrder order){
        return deliverOrderMapper.updateDeliverOrderById(order);
    }

    //删除
    public boolean deleteDeliverOrderByIds(String ids){
        String[] split = ids.split(",");
        int result = deliverOrderMapper.delDeliverOrderById(split);
        return result == split.length;
    }


}
